// 定义类方法，并实例化
{
  class Point {
    constructor (name, age) {
      this.name = name // 定义在了原型上
      this.age = age,
      this.a = () => {
        console.log('aaa')
      }
    }
    run () { // 这种方法定义在了实例上
      console.log(`name: ${this.name} age: ${this.age} runing...`)
    }
  }
  const po = Reflect.construct(Point, ['lee', 26])
  // const po = new Point('lee', 26)
  console.log(po)
  console.log(Reflect.ownKeys(Point)) // [ 'length', 'prototype', 'name' ]
  console.log(Reflect.ownKeys(Point.prototype)) // [ 'constructor', 'run' ]
  console.log(Reflect.ownKeys(Reflect.getPrototypeOf(po))) //  [ 'constructor', 'run' ]
}


// 存取函数
{
  class myClass {
    constructor () {}
    get prop () {
      return 'getter'
    }
    set prop (value) {
      console.log('setter ' + value)
    }
  }
  let ins = Reflect.construct(myClass, [])
  console.log(ins)
  console.log(ins.prop) // getter
  ins.prop = 'newProp' // setter newProp
}

// class中的Generator方法
{
  class foo {
    constructor (...args) {
      console.log(args) // [ 'hello', 'world' ]
      this.args = args
    }
    * [Symbol.iterator] () {
      for (let arg of this.args) {
        yield arg
      }
    }
  }

  for (let x of new foo ('hello', 'world')) {
    console.log(x) // hello world
  }
}

// 静态方法
{
  class Foo {
    static classMethod () {
      return 'hello'
    }
  }

  class Bar extends Foo{}
  console.log(Bar.classMethod()) // hello


  // 静态方法也可以从super对象上调用
  class Bar2 extends Foo {
    static method () {
      return super.classMethod() + ', too'
    }
  }
  console.log(Bar2.method()) // hello, too
}

// 静态属性  目前只有这种写法可行，因为ES6明确规定，class内部只有静态方法，没有静态属性
{
  class foo {}
  foo.prop = 1
  console.log(foo.prop) // 1
}
